//夜间免打扰页面
myApp.onPageInit("moon", function (page) {
    console.log("moon init");
    var pageCon = $$(page.container);

    pageCon.find('.label-switch input[type="checkbox"]').on("change", function(e){
        var checked = $$(this).prop("checked");
        if(checked) {
            $$(this).parents(".item-content").removeClass("disable");
        } else {
            $$(this).parents(".item-content").addClass("disable");
        }
    }); 
});
 
//夜间免打扰时间段设置页面
myApp.onPageInit("moonsetting", function (page) {
    console.log("moonsettingPage init");
    var pageCon = $$(page.container);
    var today = new Date();

    var repeatDayArr = [];

    // 开始时间
    var timePickerBegin = myApp.picker({
        input: '#time-picker-begin',
        container: '#time-picker-begin-container',
        toolbar: false,
        rotateEffect: false,
        value: [today.getHours(), (today.getMinutes() < 10 ? '0' + today.getMinutes() : today.getMinutes())],
        onChange: function (picker, values, displayValues) {
            //console.log("begintime:" + values)
        },
        formatValue: function (p, values, displayValues) {
            return values[0] + ' : ' + values[1];
        },
        cols: [
            // Hours
            {
                values: (function () {
                    var arr = [];
                    for (var i = 0; i <= 23; i++) {
                        arr.push(i);
                    }
                    return arr;
                })(),
            },
            // Divider
            {
                divider: true,
                content: '时&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
            },
            // Minutes
            {
                values: (function () {
                    var arr = [];
                    for (var i = 0; i <= 59; i++) {
                        arr.push(i < 10 ? '0' + i : i);
                    }
                    return arr;
                })(),
            },
            // Divider
            {
                divider: true,
                content: '分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
            },
        ]
    });

    //结束时间
    var timePickerEnd = myApp.picker({
        input: '#time-picker-end',
        container: '#time-picker-end-container',
        toolbar: false,
        rotateEffect: false,
        value: [today.getHours(), (today.getMinutes() < 10 ? '0' + today.getMinutes() : today.getMinutes())],
        onChange: function (picker, values, displayValues) {
            //console.log("endtime:" + values)
        },
        formatValue: function (p, values, displayValues) {
            return values[0] + ' : ' + values[1];
        },
        cols: [
            // Hours
            {
                values: (function () {
                    var arr = [];
                    for (var i = 0; i <= 23; i++) {
                        arr.push(i);
                    }
                    return arr;
                })(),
            },
            // Divider
            {
                divider: true,
                content: '时&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
            },
            // Minutes
            {
                values: (function () {
                    var arr = [];
                    for (var i = 0; i <= 59; i++) {
                        arr.push(i < 10 ? '0' + i : i);
                    }
                    return arr;
                })(),
            },
            // Divider
            {
                divider: true,
                content: '分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
            },
        ]
    });
    
    pageCon.find('.day-switch input[type="checkbox"]').on('change', function(e){
        var checked = $$(this).prop("checked");
        var value = $$(this).next('span').text();
        if(checked) {
            repeatDayArr.push(value);
        } else {
            repeatDayArr.splice($.inArray(value,repeatDayArr), 1);
        }
    });

    pageCon.find('.flat-button').on('click', function(e){
        myApp.confirm("repeatDay:"+ repeatDayArr+ "," +timePickerBegin.value + "-" + timePickerEnd.value, "提示")
    });
});